import logging

def get_logger(level='WARN', save_path='invoice.log'):
    save_path = save_path.replace('.py', '.log')
    logger = logging.getLogger(save_path)
    logger.setLevel(level)
    BASIC_FORMAT = "[%(asctime)s:%(filename)s:%(lineno)s:%(levelname)s]: %(message)s"
    DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
    formatter = logging.Formatter(BASIC_FORMAT, DATE_FORMAT)
    chlr = logging.StreamHandler()  # 输出到控制台的handler
    chlr.setFormatter(formatter)
    fhlr = logging.FileHandler(save_path, encoding='utf-8')  # 输出到文件的handler
    fhlr.setFormatter(formatter)
    logger.addHandler(chlr)
    logger.addHandler(fhlr)
    return logger
